limsResult.backTrackPage = {

    getTreeGrid : function(){
        var _this = this,columns = limsResult.getTreeColumns(),requestData = this.param;
        return {
            type : 'tree',
            id : 'sample-code-tree-list',
            name : 'MODULE.BUSINESS.ORDERTASK.TAB.SAMPLE_INFO',
            requestData : requestData,
            async : false,
            url : limsResult.sampleUrl + '/tree/{parentId}',
            onNodeSelected : function () {
                Gikam.getAsyncComp('sample-code-tree-list').done(function (tree) {
                    var nodeData = tree.options.selectedNodeData;
                    Gikam.getAsyncComp('back-track-order-task-grid').done(function (grid) {
                        grid.refresh({
                            url : limsResult.sampleUrl + '/sample/order-task',
                            requestData : {
                                sampleCode_EQ : nodeData.sampleCode,
                            }
                        });
                    })
                })
            }
        }
    },

    getOrderTaskGrid : function(){
        var _this = this;
        return {
            type : 'grid',
            id : 'back-track-order-task-grid',
            page : false,
            columns : limsResult.getBackOrderTaskColumns(),
            checkOnActive : true,
            onCellClick: function (field, row) {
                field === 'ext$.runcode' && _this.loadRunOrderTaskPage(row);
            },
            onLoadSuccess : function (data) {
                if (!Gikam.isEmpty(data)){
                    this.activeRowByIndex(0);
                }else{
                    _this.loadTabList();
                }
            },
            onRowActive : function (index,row) {
                _this.loadTabList(row);
            }
        }
    },

    loadRunOrderTaskPage: function (row) {
        if (Gikam.isEmpty(row) || Gikam.isEmpty(row.ext$.runid)) {
            return false;
        }
        Gikam.create('modal', {
            title: 'LIMS.MODAL.RUNDETAIL',
            url: limsResult.baseUrl + '/page/run-order-task-readonly-detail' + Gikam.param({
                id: row.ext$.runid,
                runCode: row.ext$.runcode,
                // 以弹窗的形式展示详情，各组件为只读模式
                readonly: true
            })
        });
    },

    loadTabList : function(row){
        //加载分析结果
        Gikam.getAsyncComp('back-track-analyte-list-grid').done(function (grid) {
            if (row){
                grid.setOptions({
                    url : limsResult.baseUrl + '/queries/custom',
                    requestData : {
                        orderTaskId_EQ : row.id
                    }
                });
                grid.refresh();
            }else{
                grid.cleanData();
            }
        });
        //加载分析结果记录
        Gikam.getAsyncComp('back-track-record-list-grid').done(function (grid) {
            if (row){
                grid.setOptions({
                    url : Gikam.printf(limsResult.baseUrl + '/queries/atrecord/{tableName}/{id}',{
                        tableName : 'T_LIMS_RESULT',
                        id : row.id
                    })
                });
                grid.refresh();
            }
        });
        //加载Run附件
        if (Gikam.isNotEmpty(row) && Gikam.isNotEmpty(row.ext$.runid)){
            Gikam.getAsyncComp('back-track-uploader').done(function(uploader) {
                uploader.setOptions({
                    bizId : row.ext$.runid
                });
            })
        }else{
            Gikam.getAsyncComp('back-track-uploader').done(function(uploader) {
                uploader.setOptions({
                    bizId : -1
                });
            })
        }

    },

    getTabParam : function(){
        return {
            id : 'back-track-tabs',
            type : 'tab',
            fill : true,
            panels : [{
                title : 'MODULE.BUSINESS.RESULT.TAB.BACKTRACK.ANALYTERESULT',
                items : [{
                    type : 'grid',
                    id : 'back-track-analyte-list-grid',
                    order : { sorter : 'asc' },
                    columns : limsResult.getBackTrackAnalyteColumns()
                }]
            },{
                title : 'MODULE.BUSINESS.RESULT.TAB.BACKTRACK.ATRECORD',
                items : [{
                    type : 'grid',
                    id : 'back-track-record-list-grid',
                    columns : limsResult.getBackTrackRecordColumns()
                }]
            },{
                title : 'GIKAM.FILE.ATTACHMENT',
                items : [{
                    type : 'uploader',
                    id : 'back-track-uploader',
                    dbTable : 'T_LIMS_RUN',
                    readonly : true,
                    bizCategory : 'UPLOADER',
                    filter : false,
                    genericQuery : false,
                }]
            }]
        }
    },

    create : function(){
        var _this = this;
        Gikam.create('layout',{
            id : 'result-back-track-edit-list-grid',
            renderTo : Gikam.getLastModal().window.$dom,
            west : {
                width : '30%',
                items : [_this.getTreeGrid()]
            },
            center : {
                items : [{
                    type : 'layout',
                    north : {
                        height : '40%',
                        items : [_this.getOrderTaskGrid()]
                    },
                    center : {
                        items : [_this.getTabParam()]
                    }
                }]
            }
        })
    },

    init : function (param) {
        this.param = param;
        this.create();
    }
}